Analysis of Nonlinear Constraints in CLP(R)

نویسنده

  • Michael Hanus
چکیده

information about the variables of one clause but during the concrete computation the accumulated constraints may contain nonlinear parts from arbitrary clauses. Since we are interested in the analysis of all nonlinear constraints, we will show in Theorem 3 that the nonlinear constraints with variables outside dom(A) are also covered by the abstraction A. Since our abstract interpretation algorithm always simpli es the computed abstractions by the normalization rules of Section 3.1, it is important that these rules are invariant w.r.t. the concrete interpretation of abstractions. In fact, it can be shown that (A) = (A0) if A! A0 [9]. All operations on the abstract domain must be monotone to ensure the the termination of the abstract interpretation algorithm. Hence we de ne the following order relation on normalized abstractions: (a) ?v for all 2 A (b) A v A0 () 1. V 0)X 2 A0 =) 9V V 0 with V)X 2 A 2. delay(Xor Y ) 2 A ) delay(X or Y ) 2 A0 3. delay 2 A ) delay 2 A0 It is easy to prove that v is a re exive, transitive and anti-symmetric relation on normalized abstractions. Moreover, the operation t de ned in Section 3.2 computes the least upper bound of two abstractions, and and all abstract operations de ned in Section 3.2 are monotone functions. Following the framework presented in [3], the correctness of the abstract interpretation algorithm can be proved by showing the correctness of each basic operation of the algorithm (like abstract constraint solving, clause entry and clause exit). Correctness means in this context that all concrete computations, i.e., the results of the concrete constraint solving, clause entry and clause exit (cf. Section 2) are subsumed by the abstractions computed by the corresponding abstract operations. The precise formulations and proofs of these properties can be found in [9]. There is one remaining problem with our abstract interpretation algorithm. The main motivation of this paper is the characterization of a class of CLP(R) programs where all nonlinear constraints become linear during the computation. If we analyse a CLP(R) program with our algorithm, the absence of delay elements in the success abstraction of the goal does not necessarily indicate that there are no delayed nonlinear constraints at the end of the computation. Due to the de nition of our concretisation function , this indicates that there are no delayed nonlinear constraints containing goal variables. But it does not exclude the case that there are delayed constraints with variables local to some clauses. The next theorem shows that this case cannot occur since all delayed constraints are covered by our algorithm. We need the notion of \equivalence" of variables w.r.t. a constraint to formulate this theorem. We call two variables X; Y equivalent w.r.t. constraint C, denoted X CY , if C constrains X and Y to the same values, i.e., (X) = (Y ) for all 2 Sol(C). Theorem 3 (Completeness of delay abstractions) Let L be a at literal or constraint with abstraction A and A0 = ai(A;L). Let C 2 (A) and C0 2 (A0) with C 0 = C [ CL where CL are the new constraints added to C during the execution of L. Then delay 2 A0 or for all Z=Z1*Z2 2 CL with Z1*Z2 nonlinear in C 0 there exists delay(Z 0 1 or Z 0 2) 2 A0 with Z1 C0Z0 1 and Z2 C0Z0 2. 11 Due to this theorem our abstract interpretation algorithm characterizes a class of CLP(R) programs (those containing no new delay elements in the success abstraction of the goal) for which all nonlinear constraints become linear at run time. 5 Extension to other delayed constraints In Section 2 we have de ned the subclass of CLP(R) programs which we can analyse by our abstract interpretation algorithm. However, CLP(R) programs may also contain the arithmetic functions /, sin, cos, pow, abs, min and max which are also delayed until particular conditions are satis ed. For instance, the constraint Z=sin(X) is delayed until X is ground while the constraint Z=abs(X) is delayed until X is ground, Z=0 or Z is ground and negative [11]. Since the exact value of a ground variable is not available in our abstract domain, we can only approximate this behaviour. In order to analyse these new constraints we have to extend our algorithm as follows: 1. De ne a new element in the abstract domain appropriate to the abstract description of the delayed constraint. 2. Extend the abstract constraint solver ai-con to the new constraint. 3. Extend the normalization rules for abstractions to describe the wakeup conditions of the delayed constraint. We demonstrate the necessary extensions by the new constraint Z=min(X,Y). This constraint delays until X and Y are ground. Therefore we introduce the element delay(Xand Y) in our abstract domain and extend the de nition of ai-con to: ai-con(A; Z=min(X,Y)) = A [ f fX,Yg)Z; delay(X and Y) g The wakeup condition for such constraints is described by the following normalization rule: A [ fX; Y; delay(X and Y )g ! A [ fX; Y g All other types of delayed constraints can be handled in a similar way. Although we have not explicitly mentioned the necessary changes to exit, it is obvious how to adapt the de nition of exit to the new kinds of constraints. 6 Applications We have presented an algorithm to approximate the potential run-time occurrences of nonlinear constraints in a CLP(R) program. In this section we will outline possible applications of this algorithm. 6.1 Better user support In CLP(R) the programmer can formulate arbitrary arithmetic constraints. However, during the computation process only linear arithmetic constraints are actively used to restrict the search space and control the computation. The programmer is responsible for writing the programs in such a way that all nonlinear constraints become linear during the computation. If this is not the case, the programmay stop with a set of complex nonlinear constraints for which the satis ability is di cult to decide. Unfortunately, it is not easy to see whether constraints become linear because this depends on the data ow and the constraint solving in the program. Our algorithm is able to support the user in this di cult question since the algorithm can be applied in the following ways: 12 1. We start the algorithm with a particular goal and an initial abstraction. If the success abstraction computed for this goal contains no delay elements, then all computed answer constraints are linear, i.e., the CLP(R) constraint solver can decide the satis ability of the nal answer. Conditionally successful answers [11] cannot occur in this case. 2. If the user is interested not only in the nal answer constraints but also in constraints produced during the computation process, we start the algorithm with a goal and an abstraction and consider at the end of the abstract interpretation the call and success abstractions of all literals in the program. Since these abstractions are valid approximations of all constraints which occur at run time, we can infer properties of intermediate constraints. For instance, if none of these abstractions contains a delay element, the programmer can be sure that the CLP(R) constraint solver decides the satis ability of all constraints during the entire execution and thus useless derivations with unsolvable nonlinear constraints are not explored. On the other hand, delay elements in some abstraction indicate the program points where nonlinear constraints may occur at run time. This can be a useful information for the programmer.6 6.2 More e cient implementations The knowledge about the potential presence of nonlinear constraints can be used to optimize the implementation of logic programs with arithmetic constraints. In this case it is necessary to consider the call and success abstractions of all literals rather than the success abstraction of the main goal (similarly to item 2 in Section 6.1 above). There are at least two potential optimizations: 1. If none of the abstractions contains a delay element, nonlinear constraints cannot occur at run time. Therefore general instructions for creating nonlinear constraints can be specialized to simpler instructions for creating linear constraints [14] and the program can be compiled without the delay mechanism for nonlinear constraints [16]. 2. In the RISC-CLP(Real) system [12] nonlinear arithmetic constraints are not delayed but checked by a powerful constraint solver. But this constraint solver is very complex and sometimes too ine cient for solving simple linear constraints. We can optimize the RISC-CLP(Real) system by computing the program points where nonlinear constraints may occur and where all constraints are de nitively linear. Then we can call a more e cient linear constraint solver for the latter program points without restricting the computational power of the RISC-CLP(Real) system. 6.3 Improving the termination behaviour One of the principles of constraint logic programming is the satis ability check during computation: a derivation proceeds only if all accumulated constraints are solvable [13]. This allows an early failure detection and avoids in nite derivation paths which may be present in pure logic programming. However, 6For such an application it may be necessary to change the de nition of call so that delay elements are passed into the applied clause. Then the potential presence of nonlinear constraints can be immediately seen by considering the local abstraction without including the abstractions of ancestor nodes in the tree. 13 in CLP(R) this advantage is sometimes lost since nonlinear constraints are not checked for satis ability. For instance, consider the following CLP(R) program for computing factorial numbers: fac(0,1). fac(N,N*F) :N >= 1, fac(N-1,F). To compute a factorial we start with the goal ?-fac(8,F) and obtain the answer constraint F=40320. If we want to know whether a given number is a factorial, we try to prove a goal like ?-fac(N,24). In this case CLP(R) computes the answer constraint N=4 after some backtracking steps. Although nonlinear constraints are generated during this computation, they become linear if the rst clause is used and binds the unknown rst argument. But if we try to prove a (unsolvable) goal like ?-fac(N,10), CLP(R) runs into an in nite loop by applying the second clause again and again. The accumulated nonlinear constraints are not solvable but this is not detected by CLP(R) due to the delay mechanism. If we use a more powerful constraint solver which is able to treat nonlinear constraints (like in CAL [2] or RISC-CLP(Real) [12]), this in nite loop can be avoided. We can use our abstract interpretation algorithm to nd such sources of nontermination. For this purpose we compute the call abstraction of each literal in the program. If the abstraction of a recursive call contains a delay element, either we warn the user that there may be delayed nonlinear constraints before the recursive call (which can cause an in nite loop if these constraints are not solvable), or we use a powerful constraint solver for nonlinear constraints before the recursive call at run time in order to avoid the described source of nontermination. This seems to be a good compromise between the e ciency of the CLP(R) system and the power of the RISCCLP(Real) system. 7 Conclusions and related work We have presented a method for the analysis of nonlinear constraints occurring at run time in the execution of a CLP(R) program. Since an exact analysis is impossible at compile time, we have used an abstract interpretation algorithm to approximate the possible delayed nonlinear constraints and the variable dependencies occurring at run time. The application of this algorithm to various examples shows that our algorithm has enough precision for practical programs. The information produced by this algorithm can be used to support the programmer when using the delay mechanism of the CLP(R) system or to optimize the program when using a more powerful constraint solver like RISC-CLP(Real). We have developed our analysis algorithm on the basis of a given framework for the abstract interpretation of logic programs [3] since the operational semantics of CLP(R) is very similar to logic programming. The only di erence is the use of sets of constraints instead of substitutions. Therefore any other framework may also be applicable. Marriott and S ndergaard [19] have developed a particular framework for the abstract interpretation of constraint logic programming languages based on a denotational description of the semantics. They have also shown the application of their framework to the freeness and groundness analysis of CLP programs. However, they have not applied their method to a particular domain of constraints. Therefore they have not precisely described a solution to one of the main di culties 14 in a concrete application: the abstraction of the freeness or uniqueness ofa variable w.r.t. a given concrete set of constraints. This is one of the mainpoints addressed in this paper. We have derived uniqueness information w.r.t.arithmetic constraints over the real numbers by considering the variable de-pendencies caused by constraints. The normalization rules for our abstractdomain corresponds to constraint solving in the concrete domain.Most of the well-known abstract interpretation algorithms for the deriva-tion of groundness information of variables or mode information for predicatesin logic programs use a small number of abstract values like ground, free orany (see, for instance, [21, 22, 3] or [17] for the case of CLP(R)). Such adomain yields quite good results for many practical logic programs. But forconstraint logic programming it must be re ned since the possible reasons forthe groundness of variables are much more complicated. For instance, thearithmetic constraint X=Y+Z implies the groundness of Y if X and Z are groundbut not the groundness of Y and Z if X is ground. A typical programmingmethodology in constraint logic programming is \test and generate" [15, 23]where variables are instantiated by generators after the creation of a networkof constraints between these variables. The following simple digital circuitprogram uses this technique (recall that we assume a left-to-right strategy forthe evaluation of subgoals):p(X,Y,Z):not(X,NX),and(NX,Y,NXY),not(Z,NZ),and(NXY,NZ,1),bit(X), bit(Y), bit(Z).% generatenot(A,NA) :NA = 1-A.and(A,B,AB) :AB= A*B.bit(0).bit(1).The unique answer constraint to the goal ?-p(X,Y,Z) is X=0,Y=1,Z=0, i.e.,there are no delayed nonlinear constraints in the answer. However, a simplemode analysis as in [17] would infer that the predicate and is called with freevariables in the rst and second argument position and hence there may be adelayed nonlinear constraint at run time. In order to improve the accuracy ofthe analysis, we have used implications of the form V)X to describe depen-dencies between di erent variables. For the last example our algorithm inferthe dependencies fXg)NX, fNX,Yg)NXY and fZg)NZ (among others). Sincethe variables X, Y and Z are bound to ground terms by the last bit-literalsin the rst clause, our algorithm infers (using the variable dependencies) thatthere are no delayed nonlinear constraints in the answer. This example showsthat our algorithm has a better precision than other algorithms for groundnessanalysis which is due to the fact that grounding variables by constraint solv-ing and awakening delayed constraints can be easily described on the abstractlevel with our abstract domain.Marriott and S ndergaard have also proposed an abstract domain Propfor a more precise analysis of groundness information [20, 5]. Their domaincontains propositional formulas over the program variables and the logicalconnectives _, ^ and $. Such a domain is appropriate for pure logic pro-gramming since the groundness information after a uni cation like X=f(Y,Z)can be expressed by the propositional formula X $ Y ^ Z meaning that thegroundness of X is equivalent to the groundness of Y and Z. But in constraintlogic languages the instantiation of variables may have di erent reasons asshown above by the constraint X=Y+Z. These di erent possibilities can be15 easily expressed in our abstract domain of variable dependencies.Our abstract domain has some similarities to the abstract domain used forthe analysis of residuating logic programs [10]. This is due to the fact thatthe analysis of variable dependencies is also essential for a precise analysisof residuating logic programs. However, the meaning of abstractions is quitedi erent in both approaches. In case of residuating logic programs the con-crete domain consists of substitutions and residuated equations and thereforesubstitutions must be interpreted w.r.t. the current set of residuated equa-tions. In our case abstractions have a more direct meaning in the concretedomain and therefore the concretisation function and the correctness proofsare simpler. Further essential di erences show up in the de nition of ab-stract uni cation which is more sophisticated in the case of constraint logicprograms.Recently, Garc a de la Banda and Hermenegildo [8] have independentlydeveloped a framework for the analysis of constraint logic programs by extend-ing Bruynooghe's framework. Although they were mainly interested in thederivation of groundness information and did not include information aboutnonlinear constraints in their abstract domain, the abstract representation ofvariable dependencies is very similar to our approach. They also associateto each variable sets of variables which uniquely determine the value of thatvariable. However, they have given a direct de nition of abstract constraintsolving which results in more complicated de nitions than our approach usingnormalization rules to simplify abstractions after abstract constraint solving.Although our algorithm yields quite good results for practical programs,the precision of the uniqueness analysis can be improved in various ways.For instance, we do not consider the free variables in constraints and thuswe do not detect the uniqueness of these variables in some cases. E.g., theconstraint 3=5*X-2*X restricts variable X to the unique value 1. But our anal-ysis algorithm does not infer that X is unique since the information that bothsubexpressions contain the same free variable is not present in the correspond-ing abstraction. Hence the analysis can be improved if the abstract domain isre ned to store information about variables in expressions. Another possibil-ity for improving the precision of the analysis is to derive information aboutpossible values of variables. This would allow to detect that the constraintsX=3,6=X*Y restricts Y to a unique value or that the constraints X>2,Z=1,Xare unsolvable.Acknowledgements. This research was supported in part by the German Ministryfor Research and Technology (BMFT) under grant ITS 9103 and by the ESPRITBasic Research Working Group 6028 (Construction of Computational Logics). Theresponsibility for the contents of this publication lies with the author.References[1] S. Abramsky and C. Hankin, editors. Abstract Interpretation of DeclarativeLanguages. Ellis Horwood, 1987.[2] A. Aiba, K. Sakai, Y. Sato, D.J. Hawley, and R. Hasegawa. Constraint LogicProgramming Language CAL. In Proc. Int. Conf. on Fifth Generation Com-puter Systems, pp. 263{276, 1988.[3] M. Bruynooghe. A Practical Framework for the Abstract Interpretation of LogicPrograms. Journal of Logic Programming (10), pp. 91{124, 1991.[4] A. Colmerauer. An Introduction to Prolog III. Communications of the ACM,Vol. 33, No. 7, pp. 69{90, 1990. 16 [5] A. Cortesi, G. File, andW.Winsborough. Prop revisited: Propositional Formulaas Abstract Domain for Groundness Analysis. In Proc. IEEE Symposium onLogic in Computer Science, pp. 322{327, 1991.[6] P. Cousot and R. Cousot. Abstract interpretation: A uni ed lattice model forstatic analysis of programs by construction of approximation of xpoints. InProc. of the 4th ACM Symposium on Principles of Programming Languages, pp.238{252, 1977.[7] S.K. Debray. Static Inference of Modes and Data Dependencies in Logic Pro-grams. ACM Transactions on Programming Languages and Systems, Vol. 11,No. 3, pp. 418{450, 1989.[8] M.J. Garc a de la Banda and M. Hermenegildo. A Practical Approach to theGlobal Analysis of Constraint Logic Programs. Technical Report, UniversidadPolitecnica de Madrid, 1992.[9] M. Hanus. Analysis of Nonlinear Constraints in CLP(R). Technical ReportMPI-I-92-251, Max-Planck-Institut fur Informatik, Saarbrucken, 1992.[10] M. Hanus. On the Completeness of Residuation. In Proc. of the 1992 JointInternational Conference and Symposium on Logic Programming, pp. 192{206.MIT Press, 1992.[11] N. Heintze, J. Ja ar, S. Michaylov, P. Stuckey, and R. Yap. The CLP(R)Programmer's Manual, Version 1.1. IBM Thomas J. Watson Research Center,Yorktown Heights, 1991.[12] H. Hong. Non-linear Real Constraints in Constraint Logic Programming. InProc. of the 3rd International Conference on Algebraic and Logic Programming,pp. 201{212. Springer LNCS 632, 1992.[13] J. Ja ar and J.-L. Lassez. Constraint Logic Programming. In Proc. of the14th ACM Symposium on Principles of Programming Languages, pp. 111{119,Munich, 1987.[14] J. Ja ar, S. Michaylov, P.J. Stuckey, and R.H.C. Yap. An Abstract Machinefor CLP(R). In Proc. SIGPLAN Conference on Programming Language Designand Implementation, pp. 128{139. SIGPLAN Notices, Vol. 27, No. 7, 1992.[15] J. Ja ar, S. Michaylov, P.J. Stuckey, and R.H.C. Yap. The CLP(R) Lan-guage and System. ACM Transactions on Programming Languages and Sys-tems, Vol. 14, No. 3, pp. 339{395, 1992.[16] J. Ja ar, S. Michaylov, and R.H.C. Yap. A Methodology for Managing HardConstraints in CLP Systems. In Proc. ACM SIGPLAN'91 Conference on Pro-gramming Language Design and Implementation, pp. 306{316. SIGPLAN No-tices, Vol. 26, No. 6, 1991.[17] N. J rgensen, K. Marriott, and S. Michaylov. Some Global Compile-Time Op-timizations for CLP(R). In Proc. 1991 International Logic Programming Sym-posium, pp. 420{434. MIT Press, 1991.[18] B. Le Charlier, K. Musumbu, and P. Van Hentenryck. A Generic AbstractInterpretation Algorithm and its Complexity Analysis. In Proc. InternationalConference on Logic Programming, pp. 64{78. MIT Press, 1991.[19] K. Marriott and H. S ndergaard. Analysis of Constraint Logic Programs. InProc. of the 1990 North American Conference on Logic Programming, pp. 531{547. MIT Press, 1990.[20] K. Marriott, H. S ndergaard, and P. Dart. A Characterization of Non-Floundering Logic Programs. In Proc. of the 1990 North American Conferenceon Logic Programming, pp. 661{680. MIT Press, 1990.[21] C.S. Mellish. Some Global Optimizations for a Prolog Compiler. Journal ofLogic Programming (1), pp. 43{66, 1985.[22] U. Nilsson. Towards a Framework for the Abstract Interpretation of LogicPrograms. In Proc. of the Workshop on Programming Language Implementationand Logic Programming, pp. 68{82, Orleans, 1988. Springer LNCS 348.[23] P. Van Hentenryck. Constraint Satisfaction in Logic Programming. MIT Press,1989.17

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Max-planck-institut F ¨ Ur Informatik Analysis of Nonlinear Constraints in Clp(r) I N F O R M a T I K Author's Address

Solving nonlinear constraints over real numbers is a complex problem. Hence constraint logic programming languages like CLP(R) or Prolog III solve only linear constraints and delay nonlinear constraints until they become linear. This efficient implementation method has the disadvantage that sometimes computed answers are unsatisfiable or infinite loops occur due to the unsatisfiability of delay...

متن کامل

A Methodology for Managing Hard

In constraint logic programming (CLP) systems, the standard technique for dealing with hard constraints is to delay solving them until additional constraints reduce them to a simpler form. For example, the CLP(R) system delays the solving of nonlinear equations until they become linear, when certain variables become ground. In a naive implementation , the overhead of delaying and awakening cons...

متن کامل

STAN: A Static Analyzer for CLP(R) Based on Abstract Interpretation

Stan is an implementation of a static analysis for CLP(R) based on abstract interpretation. The semantics of the program is achieved using unfolding operator. The abstract domain is a space of convex poly-hedra. Three types of program analysis are implemented-backward, forward and combined.The results of the analysis can be used in program optimization. The implementation is complemented by a g...

متن کامل

QUAD-CLP(R): Adding the Power of Quadratic Constraints

We report on a new way of handling non-linear arithmetic constraints and its implementation into the QUAD-CLP(R) language. Important properties of the problem at hand are a discretization through geometric equivalence classes and decomposition into convex pieces. A case analysis of those equivalence classes leads to a relaxation (and sometimes recasting) of the original constraints into linear ...

متن کامل

Compiling Constraints in clp(FD)

We present the clp(FD) system: a Constraint Logic Programming language with finite domain constraints. We detail its implementation and present an abstract instruction set for the constraint solver that can be smoothly integrated into the WAM architecture. It is based on the use of a single primitive constraintX in r that embeds the core propagation mechanism. Complex user constraints such as l...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 1993